<template>
	<!-- 鉴定申请 -->
	<view class="page">
		<view class="top" @click="goToExample">
			<view class="top_l">
				<image class="look_icon" src="/static/common/look_Icon.png" mode=""></image>
				<view>鉴定范本查看</view>
			</view>
			<u-icon name="arrow-right" color="#FFFFFF" size="32rpx"></u-icon>
		</view>

		<view class="main">
			<view class="title">鉴定类型</view>
			<view class="radio">
				<view class="radio_item" @click="form.itemType=1">
					<image v-if="form.itemType==1" class="radio_icon" src="/static/common/radio-a.png" mode=""></image>
					<image v-else class="radio_icon" src="/static/common/radio.png" mode=""></image>
					<view>球鞋鉴定</view>
				</view>
				<view class="radio_item" @click="form.itemType=2">
					<image v-if="form.itemType==2" class="radio_icon" src="/static/common/radio-a.png" mode=""></image>
					<image v-else class="radio_icon" src="/static/common/radio.png" mode=""></image>
					<view>奢潮鉴定</view>
				</view>
			</view>

			<view class="title">鉴定图片</view>
			<view class="upload">
				<c-upLoadImgs :file.sync="form.itemImage" maxCount="15" />
			</view>

			<view class="title">添加备注</view>
			<view class="textarea">
				<u--textarea v-model="form.itemRemark" placeholder="请输入"></u--textarea>
			</view>
		</view>
		<view class="summarize">
			<view class="title">账号总结</view>
			<view class="card">
				<view class="card_l">我的次卡可用</view>
				<view class="card_r">{{uses}}</view>
			</view>
			<view class="card">
				<view class="card_l">本次扣费</view>
				<view class="card_r">{{need}}</view>
			</view>
		</view>
		<view class="btn-box">
			<button class="btn" @click="submit">立即提交</button>
		</view>

		<u-popup :show="rechargeShow" mode="center" bgColor="transparent">
			<view class="tips">
				<image class="tips_icon" src="/pages/home/static/tips_icon.png" mode=""></image>
				<view class="tips_c">您的次卡次数不足</view>
				<view class="tips_c">请前去充值</view>
				<view class="tips_btns">
					<view class="btn btn1" @click="rechargeShow=false">取消</view>
					<view class="btn btn2" @click="gotoTopUp">去充值</view>
				</view>
			</view>
		</u-popup>

		<u-popup :show="successShow" mode="center" bgColor="transparent">
			<view class="tips">
				<view class="tips_c">订单提交成功</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	import form from '../../../uni_modules/uview-ui/libs/config/props/form';
	export default {
		name: "appraisalApply",
		data() {
			return {
				rechargeShow: false,
				successShow: false,
				uses: null,
				form: {
					itemType: 1,
					itemImage: [],
					itemRemark: ''
				},
			};
		},
		onLoad() {},
		onShow() {
			this.getUses()
		},
		computed: {
			// 计算属性来根据form.itemType动态计算need的值
			need() {
				// 如果form.itemType是null或未定义，则默认为1，否则为form.itemType + 1
				return this.form.itemType === 1 ? 1 : 3;
			}
		},
		methods: {
			gotoTopUp() {
				uni.switchTab({
					url: '/pages/tabbar/topUp'
				});
			},
			getUses() {
				this.$api.getUses().then(res => {
					console.log(res, '次卡使用次数')
					this.uses = res.data
				})
			},
			submit() {
				console.log(this.form, '订单数据')
				if (this.uses < this.need) {
					this.rechargeShow = true;
				} else {
					this.$api.addOrder(this.form).then(res => {
						console.log('保存');
						uni.$u.toast('订单提交成功');
						this.getUses();
						setTimeout(() => {
							uni.navigateBack()
						}, 2000)

					})
				}
			},
			goToExample() {
				let param = this.form.itemType === 1 ? 0 : 1; // 根据鉴定类型设置参数
				this.$fn.jumpPage(`./example?param=${param}`); // 调用jumpPage并传递参数
			}
		}
	};
</script>

<style lang="scss" scoped>
	.top {
		width: 750rpx;
		height: 96rpx;
		background: #000000;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 32rpx;
		box-sizing: border-box;

		.top_l {
			display: flex;
			align-items: center;
			gap: 16rpx;
			font-size: 28rpx;
			color: #FFFFFF;


			.look_icon {
				width: 28rpx;
				height: 28rpx;
			}

		}
	}

	.main {
		padding: 32rpx;
		box-sizing: border-box;
		border-bottom: 10rpx solid #F7F8FA;

		.title {
			font-weight: bold;
			font-size: 32rpx;
			color: #1A1A1A;
		}

		.radio {
			display: flex;
			align-items: center;
			gap: 80rpx;
			margin: 24rpx 0 48rpx;

			.radio_item {
				display: flex;
				align-items: center;
				gap: 10rpx;

				.radio_icon {
					width: 28rpx;
					height: 28rpx;
				}

			}

		}

		.upload {
			margin: 20rpx 0 48rpx;
		}

		.textarea {
			margin: 20rpx 0 0rpx;
		}


	}

	.summarize {
		padding: 32rpx;
		box-sizing: border-box;

		.title {
			font-weight: bold;
			font-size: 32rpx;
			color: #1A1A1A;
			margin-bottom: 28rpx;
		}

		.card {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 28rpx;
			margin-bottom: 20rpx;

			.card_l {
				font-weight: 400;
				color: #666666;
			}

			.card_r {
				font-weight: bold;
				color: #333333;
			}
		}
	}

	.tips {
		width: 480rpx;
		height: 520rpx;
		background: linear-gradient(360deg, #FFFFFF 0%, #D9FFF7 100%);
		border-radius: 32rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.tips_icon {
			width: 160rpx;
			height: 160rpx;
			margin: 40rpx 0;
		}

		.tips_c {
			font-weight: bold;
			font-size: 36rpx;
			color: #000000;
		}

		.tips_btns {
			display: flex;
			align-items: center;
			gap: 32rpx;
			margin-top: 60rpx;

			.btn {
				width: 184rpx;
				height: 80rpx;
				border-radius: 12rpx;
				font-size: 32rpx;
				line-height: 80rpx;
				text-align: center;
			}

			.btn1 {
				background: #E6E6E6;
				color: #333333;
			}

			.btn2 {
				background: #1A1A1A;
				color: #FFFFFF;
			}
		}
	}
</style>